// SPDX-License-Identifier: Mulan PSL v2
/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This software is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

pub mod types {
    pub mod xgpu_recorder {
        pub mod v1 {
            // Include generated protobuf code
            include!(concat!(env!("OUT_DIR"), "/xgpu.journal.v1.rs"));

            // Magic number constants
            pub const JOURNAL_MAGIC: u32 = 0x78475055; // "xGPU"

            use rustix::system;

            // Add convenience constructor for SystemContext
            impl SystemContext {
                pub fn new() -> Self {
                    Self {
                        hostname: system::uname().nodename().to_string_lossy().into_owned(),
                        process_id: std::process::id(),
                        process_name: std::env::current_exe()
                            .ok()
                            .and_then(|p| p.file_name().map(|n| n.to_string_lossy().to_string()))
                            .unwrap_or_else(|| "unknown".to_string()),
                        cuda_version: Some(String::from("12.2.140")),
                        driver_version: Some(String::from("535.104.05")),
                        toolkit_version: Some(String::from("12.2")),
                    }
                }
            }

            // Add convenience constructor for RecorderHeader
            impl RecorderHeader {
                pub fn new() -> Self {
                    Self {
                        magic: JOURNAL_MAGIC,
                        version: Some(RecorderVersion {
                            major: 1,
                            minor: 0,
                            patch: Some(0),
                        }),
                        timestamp_ns: std::time::SystemTime::now()
                            .duration_since(std::time::UNIX_EPOCH)
                            .unwrap_or_default()
                            .as_nanos() as u64,
                        context: Some(SystemContext::new()),
                    }
                }
            }
        }
    }
}

pub mod dynlink;
pub mod ipc;
pub mod recorder;
pub mod utils;
